package com.atguigu03.threadsafe.runnablesafe.runnablesage;
/*
* 同步代码块-继承
* */
public class t {
    public static void main(String[] args) {
        SaleTickets1 s1= new SaleTickets1();
        SaleTickets1 s2= new SaleTickets1();
        SaleTickets1 s3= new SaleTickets1();
        s1.setName("线程1");
        s2.setName("线程2");
        s3.setName("线程3");
        s1.start();
        s2.start();
        s3.start();
    }

}

class SaleTickets1 extends Thread{
    static int tickets=100;
    static Object object=new Object();

    @Override
    public void run() {
        while (true){
            synchronized (object) {
                if(tickets>0){
                    try {
                        Thread.sleep(10);
                    }catch (InterruptedException e){
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+"售票，票号为："+tickets);
                    tickets--;
                    //s
                }else {
                    break;
                }
            }
        }
    }
}